<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="../css/common.css"/>
    <link rel="stylesheet" href="../css/main.css"/>
    <link rel="stylesheet" href="../css/jquery-ui-timepicker-addon.css"/>
    <link rel="stylesheet" href="../css/jquery-ui.css"/>
    <link href="../css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="../css/city-picker.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="../css/jquery-impromptu.min.css" type="text/css"/>
    <title>Document</title>
    <style>

    </style>
</head>
<body>
    <div class="box">
        <div class="box_border" style="border-bottom: none;">
            <div class="box_top"><b class="pl15">部门信息</b>
            </div>
            <div style="clear: both;"></div>
            <div class="mt10">
                <div id="table" class="mt10">
                    <div class="box span9 oh" style="margin-left: 80px;">
                        <table class="form_table" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td>
                                    <div class="fr"><a class="ext_btn"  onclick="addSection()"><span class="add"></span>增加部门</a></div>
                                        <!--<input type="submit" value="增加部门" class="ext_btn ext_btn_submit" onclick="addSection()">-->
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div class="box span9 oh" style="margin-left: auto; margin-right: auto">
                            <table id="approval_info1" width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table" style="table-layout:fixed; font-size:1.2rem">
                                <tr>
                                    <th class="td_center" style="width:5%">序号</th>
                                    <!--<th class="td_center" style="width:20%">部门编号</th>-->
                                    <th class="td_center" >部门名称</th>
                                    <th class="td_center" >部门类别</th>
                                    <th class="td_center" >可选操作</th>
                                </tr>
                                <tbody id="approval_info">
                                </tbody>
                            </table>
                        <div class="page  fl" style="margin-top: -10px;">
                            <div class="pagination">
                                <ul id="ul">
                                    <li class="first-child " id="li1"><a onclick="firstLastPage(0)">首页</a></li>
                                    <li class="" id="li2"><a onclick="upDownPage(-1)">上一页</a></li>
                                    <li class="" id="li3"><a onclick="upDownPage(1)">下一页</a></li>
                                    <li class="last-child " id="li4"><a onclick="firstLastPage(1)">末页</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="addSection" style="display: none;">
        <form name="formAddSection">
            <div class="pb10 mb15"> <div style="display: inline-block;width:80px;text-align: right;" >部门级别:</div>
                <select name="section_type" class="select "   style="width: 147px;">
                    <option value="1">普通部门</option>
                    <option value="2">大案要案</option>
                </select>
            </div>
            <div class="pb10 "><div style="display: inline-block;width:80px;text-align: right;" >部门名称:</div>
                <input name="section_name" type="text"  class="input-text lh30" size="20" /><span style="color: red;">&nbsp;*</span></div>
        </form>
    </div>
<div id="info" style="display: none;">

</div>
</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/config.js"></script>
<script type="text/javascript">


    //加载表格
    function createTable(n,m){
//        var sectionData=JSON.parse(JSON.stringify([{section_ID:123045,section_name:'财务部'}]));
        var phpUrl=url+'admin/Section/SectionGetAllSectionDataLimit.php';
//        alert(phpUrl);
        $.ajax({
            url:phpUrl,
            type: "POST",
            data:{model:'getSectionDataLimit',n:n,m:m},
            success:function(allSectionData){
//                alert(allSectionData);
                allSectionData=JSON.parse(allSectionData);
                if(allSectionData['state']!=-1){
                    var sectionData=allSectionData['data'];
                    $("#approval_info").empty();
                    for (var i = 0; i < sectionData.length; i++) {
                        var sectionType='普通部门';
                        if(sectionData[i]['section_type']==2) sectionType='大案要案';
                        $("#approval_info").append(
                                '<tr><td class="td_center  " >' + (curPage*10 + i+1) + '</td>' +
//                                '<td class="td_center  " >' + sectionData[i]['section_ID'] + '</td>' +
                                '<td class="td_center  " >' + sectionData[i]['section_name'] + '</td>' +
                                '<td class="td_center  " >' + sectionType + '</td>' +
                                '<td class="td_center"><a class="ext_btn modify" onclick="sectionManger('+sectionData[i]['section_ID']+')" ><span class="modify" ></span>部门管理</a>'
                        );
                    }
                }
            }});
    }

    //添加部门
    function addSection(){
        var phpUrl=url+'admin/Section/SectionGetOneAllSectionBySectionName.php';
        $("#addSection").dialog({
            resizable:false,
            title: "添加部门",
            modal: true,
            buttons:{
                '取消':function(){
                    $("#addSection").dialog('close');
                },
                '确定':function() {
                    if (document.formAddSection.section_name.value == '') dialogInfo("部门名称为空！");
                    else {
                        $.ajax({
                            url:phpUrl,
                            type:"POST",
                            data:{model:'getOneAllSectionBySectionName',section_name:document.formAddSection.section_name.value},
                            success: function (data) {
//                                alert(data);
                                data=JSON.parse(data);
                                if(data.state==-1) dialogInfo("部门已存在！");
                                else{
                                    phpUrl=url+'admin/Section/SectionInsertToAllSection.php';
                                    $.ajax({
                                        url: phpUrl,
                                        type: "POST",
                                        data: {
                                            model: 'insertAllSection',
                                            section_name: document.formAddSection.section_name.value,
                                            section_type: document.formAddSection.section_type.value
                                        },
                                        success: function (allSectionData) {
//
                                            allSectionData = JSON.parse(allSectionData);
                                            var state = allSectionData['state'];
                                            if (state != -1) {
                                                dialogInfo("添加成功！");
                                                $("#addSection").dialog('close');
                                                getSectionPageCount();
                                                createTable(curPage*10,10);
                                            }
                                            else {
                                                dialogInfo("添加失败！");
                                                $("#addSection").dialog('close');
                                            }
                                        }
                                    });
                                }
                            }
                        });
                    }
                }
            }
        });
    }
    //消息提醒
    function dialogInfo(data){
        document.getElementById('info').innerHTML=data;
        $("#info").dialog({
            resizable:false,
            title: "信息",
            modal: true,
            buttons:{
                '确定':function(){
                    $("#info").dialog('close');
                    createTable();
                }
            }
        })
    }
    //部门管理
    function sectionManger(sectionId){
        sectionId=JSON.stringify({sectionId:sectionId});
        window.localStorage.setItem('editSectionId', sectionId);
        window.location="sectionmanager_edit.html";
    }

    //获取页数
    var pageCounts=0;
    var curPage=0;
    function getSectionPageCount(){
        var phpUrl=url+'admin/Section/SectionGetAllSectionPageCount.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:false,
            data:{model:'getSectionPageCount'},
            success: function (data) {
//                alert(data);
                data = JSON.parse(data);
                if (data.state == 1) {
                    pageCounts = Math.ceil(data.data/10);
                }
            }
        });
    }
    function getSectionDataLimit(n,m){
        var phpUrl=url+'admin/Section/SectionGetAllSectionDataLimit.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            data:{'model':'getSectionDataLimit','n':n,'m':m},
            success: function (data) {
                data = JSON.parse(data);
                if(data['state']==1){
                    createTable(n,m);
                }
            }
        });
    }
    //首尾跳页
    function firstLastPage(e){
        $("#ul").show();
        if(e==0) {
            curPage=0;
            $("#ul li").addClass("disabled");
            $("#li3").removeClass("disabled");
            $("#li4").removeClass("disabled");
        }
        else{
//      alert(pageCounts);
            curPage=pageCounts-1;
            $("#ul li").addClass("disabled");
            $("#li1").removeClass("disabled");
            $("#li2").removeClass("disabled");
        }
        getSectionDataLimit(curPage*10,10);
    }
    //上下翻页
    function upDownPage(e){
        $("#ul").show();
        if(curPage>=0||curpage<=pageCounts-1){
            if(e<0){
                if(curPage>0)  {
                    curPage--;
                    if(curPage>0) $("#ul li").removeClass("disabled");
                    else{
                        $("#ul li").removeClass("disabled");
                        $("#li1").addClass("disabled");
                        $("#li2").addClass("disabled");
                    }
                }
            }else{
                if(curPage<pageCounts-1) {
                    curPage++;
                    if(curPage<pageCounts-1) $("#ul li").removeClass("disabled");
                    else{
                        $("#ul li").removeClass("disabled");
                        $("#li3").addClass("disabled");
                        $("#li4").addClass("disabled");
                    }
                }
            }
            getSectionDataLimit(curPage*10,10);
        }
    }
    $(function () {
        firstLastPage(0);
        getSectionPageCount();
        if(pageCounts==1) $("#ul").hide();
    })
</script>
</html>
  